# -*- coding: utf-8 -*-

import json
import re  # 正则模块的导包

# s1 = 'python'  # str
# s2 = {'name':'python'}  # dict
# s3 = '{"name":"python"}'  # str (json格式)
# print(type(s1), type(s2), type(s3))

# dic = {"name":{"姓名":"zuoshou"}}
# print(dic['name']["姓名"])

# trs = input('请输入翻译的内容:')
# lenght = len(trs[0].encode('utf-8'))  # 中文是占3个字节  英文占了1个字节
# print(lenght)

"""
字符串类型的数据
"""
# s1 = '{"name":[{"key1":"value1"}, {"key2":"value2"}]}'  # 字典
#
# s2 = '[{"name":"python"}]'  # 列表
#
# s3 = 'jquery:[{"name":"python"}]'  #

"""
需求: 取value1  
"""
# res = json.loads(s1)
# print(type(res))

# res1 = json.loads(s2)
# print(type(res1))

# 变量名最好是见名知意
# pattern: 关键字: 正则规则
"""
想要的数据用括号括起来
. 是可以匹配任意一个字符
json.dumps: 将python对象转换成字符串
loads(): 将str转换成对应的python对象 (重点)
"""
# result = re.match('jquery:(.*)', s3)
# res2 = json.loads(result.group(1))
# print(type(res2))

# print(re.match('...', 'hello'))
#
# print(re.match('.*', '.0....ello').group())


# s1 = {"name":"python"}  # 字典数据类型
# result = json.dumps(s1)
# print(type(result))


# data = {"name":"python", "name1":"左手"}  # python对象
# with open('data.json', 'w', encoding='utf-8')as f:
#     json.dump(data, f, ensure_ascii=False) # 数据， fp = 文件对象 如果内容有中文，默认是Ascii编码写入

with open('data.json', 'r', encoding='utf-8') as f:
    data = json.load(f)  # 将字符串转换成python对象
    print(type(data),data['name1'])


"""
目标网站: https://vip.stock.finance.sina.com.cn/mkt/#bjs_root
需求: 打印输出股票名称，最新价，涨跌额，涨跌幅，买入，卖出，昨收，等数据
"""